package com.storage.common.enums;

/**
 * 角色类型
 *
 * @author wb-zh270168
 */
public enum RoleType {

    ADMIN(1, "超级管理员"),

    BUSINESS_USER(2, "系统业务员"),

    AGENT(3, "代理商"),

    SHOW_LEADER(4, "店长"),

    PURCHASE_USER(5, "采购员"),

    STOCK_USER(6, "库存管理员"),

    SELL_USER(7, "店铺销售员");

    private final int value;

    private final String desc;

    RoleType(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据 value 返回枚举
     * @param value
     * @return
     */
    public static RoleType valueOf(int value) {
        for (RoleType type : values()) {
            if (type.getValue() == value) {
                return type;
            }
        }
        return null;
    }

    /**
     * 是否是店铺人员
     * @param value
     * @return
     */
    public static boolean isWorker(int value) {
        return value == RoleType.PURCHASE_USER.getValue() || value == RoleType.SELL_USER.getValue()
                || value == RoleType.SHOW_LEADER.getValue() || value == RoleType.STOCK_USER.getValue();
    }

    /**
     * 是否代理商
     * @param value
     * @return
     */
    public static boolean isAgent(int value) {
        return value == RoleType.AGENT.getValue();
    }

    /**
     * 是否是管理员
     * @param value
     * @return
     */
    public static boolean isAdmin(int value) {
        return value == RoleType.ADMIN.getValue();
    }

    /**
     * 获取可操作性id - 代理商id 或者是 shopId
     * @param userRole
     * @param userId
     * @param shopId
     * @return
     */
    public static Long getOperationUserId(int userRole, Long userId, Long shopId) {
        if (RoleType.isAgent(userRole)) {
            return userId;
        } else if (RoleType.isWorker(userRole)) {
            return shopId;
        } else if (RoleType.isAdmin(userRole)) {
            return userId;
        }
        return null;
    }

    /**
     * 获取当前用户类型
     * @param userRole
     * @return
     */
    public static Integer getOwnerType(int userRole) {
        if (RoleType.isAgent(userRole) || RoleType.isAdmin(userRole)) {
            return OwnerType.AGENT.getValue();
        } else if (RoleType.isWorker(userRole)) {
            return OwnerType.SHOP.getValue();
        }
        return null;
    }
}
